<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Page Config->Tax
 * Edit taxes for article
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
function contentPage($refPage, $page, $subpage, $refValidate)
{
	$refPage->assign('messagebox', '');

	if (isset($_GET['func']))
	{
		if ($refValidate->cleanslash($_GET['func']) === 'edit')
		{ // edit tax
			$pagefile = 'module/page/config/tax.page.edit.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
	}
	else if (isset($_REQUEST['submit']))
	{
		if ($refValidate->cleanslash($_REQUEST['submit']) === _('Save'))
		{ // Save values from Form
			$pagefile = 'module/page/config/tax.page.save.php';
			if (is_file($pagefile))
				include_once $pagefile;

			$pagefile = 'module/page/config/tax.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('Delete'))
		{ // Delete maked Data
			/**
			 * Todo: Test if it in use. Yes? Then don't delete! Message! 
			 */
			foreach ($_POST['marker'] as $idx)
			{
				$idx = $refValidate->cleanslash($idx);
				db::getInstance()->where('tax_id', $idx);
				$result = db::getInstance()->delete('tax');
			}

			$pagefile = 'module/page/config/tax.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('New'))
		{ // Create new Datarow and open Editor
			$data = Array('tax_name' => _('New Tax'));
			$id = db::getInstance()->insert("tax", $data);
			db::getInstance()->where('tax_name', _('New Tax'));
			$result = db::getInstance()->getOne('tax');

			$_GET['id'] = $result['tax_id'];

			$pagefile = 'module/page/config/tax.page.edit.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('Cancel'))
		{ // browse tax
			$pagefile = 'module/page/config/tax.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
	}
	else
	{ // browse tax
		$pagefile = 'module/page/config/tax.page.table.php';
		if (is_file($pagefile))
			include_once $pagefile;
	}
}

?>